package com.headline.config;

import com.headline.interceptor.LoginProtectInterceptor;
//import com.headline.interceptor.MyInterceptor;
import com.headline.interceptor.MyInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private LoginProtectInterceptor loginProtectInterceptor;

    @Autowired
    private MyInterceptor myInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册第一个拦截器
        registry.addInterceptor(loginProtectInterceptor).addPathPatterns("/headline/**");

        // 注册第二个拦截器
        registry.addInterceptor(myInterceptor)
                .addPathPatterns("/**") // 拦截所有路径
                .excludePathPatterns("/static/**", "/login"); // 排除某些路径
    }
}